package com.etc.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.etc.dao.CompanyMapper;
import com.etc.entity.ComResume;
import com.etc.entity.Company;
import com.etc.entity.Job;
import com.etc.entity.Jonseeker;
import com.etc.entity.LayUiData;
import com.etc.entity.User;
import com.etc.service.ComResumeService;
import com.etc.service.CompanyService;
import com.etc.service.JobService;
import com.etc.service.JonseeService;
import com.etc.service.UserService;
import com.sun.tracing.dtrace.ModuleAttributes;

@Controller
public class CompanyController {
	
	@Autowired
	private CompanyService companyService;
	@Autowired
	private JobService jobService;
	@Autowired
	private ComResumeService crs;
	
	@GetMapping("companyCenter")
	public ModelAndView getFrame() {
		ModelAndView mv = new ModelAndView("companyCenter");
		Company company = companyService.getCompany(1);
		System.out.println("company:" + company);
		mv.addObject("company", company);
		return mv;
	}
	
	@PostMapping("updateInfo")
	public ModelAndView updateInfo(Company company,@ModelAttribute("user") User user) {
		
		System.out.println("company测试:"+company);
		//根据传回的值修改company信息
		boolean flag = companyService.updateCompany(company);
		System.out.println("flag:" + flag);
		//通过id去获取修改后的信息
		company = companyService.getCompany(company.getComId());
		System.out.println("company修改后:" + company);
		ModelAndView mv = new ModelAndView("companyCenter");
		mv.addObject("company", company);
		return mv;
	}
	
	@PostMapping("addJob")
	public ModelAndView addJob(Job job) {
		
		System.out.println("得到的job:" + job);
		int flag = jobService.addJob(job);
		System.out.println("flag:" + flag);
		ModelAndView mv = new ModelAndView("companyCenter");
		Company company = companyService.getCompany(job.getComId());
		mv.addObject("company", company);
		return mv;
	}
	
	/**
	 * 岗位管理列表
	 * @return
	 */
	@GetMapping("job_list")
	@ResponseBody
	public LayUiData<Job> jobA(@RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike") String strLike)
	{
		System.out.println(strLike);
		LayUiData<Job> layuiData = jobService.getJobByLike(page, limit, strLike);
		return layuiData;
	}
	
	/**
	 * 简历管理
	 * @return
	 */
	@GetMapping("resume_list1")
	@ResponseBody
	public LayUiData<ComResume> resumeA( @RequestParam(value="getComName") String getComName, @RequestParam(defaultValue="1", value="page") int page,@RequestParam(defaultValue="10" , value="limit") int limit,@RequestParam(defaultValue="", value="strLike1") String strLike)
	{
		LayUiData<ComResume> layuiData = crs.queryIscomName(page, limit, getComName);
		return layuiData;
	}
	
	//删除简历
	@PostMapping("delresume1")
	@ResponseBody
	public String delresume(int resumeId)
	{
		System.out.println(resumeId);
		boolean flag = crs.deleteComResume(resumeId);
		return flag+"";
	}
	//修改简历
	@PostMapping("updresume1")
	public String updresume(ComResume resume)
	{
		
		System.out.println("我进来了");
		boolean flag = crs.updateComResume(resume);
		System.out.println(flag);
		return "companyCenter";
	}

}
